const gulp = require('gulp');
const less = require('gulp-less');
const postcss = require('gulp-postcss');
const autoprefixer = require('autoprefixer');
const cssnano = require('cssnano');



const lessSource = './src/less/**/*.less';

const plugins = [
   cssnano(),
   autoprefixer({ overrideBrowserslist: ['last 1 version'] }),
];

// 定义一个任务来编译LESS文件
gulp.task('less', function () {
  return gulp.src(lessSource)
    .pipe(less())
    .pipe(postcss(plugins))
    .pipe(gulp.dest('./src/css'));
});

gulp.task('less:watch', function () {
   gulp.watch(lessSource, gulp.parallel('less'));
});

gulp.task('start', gulp.parallel('less', 'less:watch'));